<?php
/**
 * Created by PhpStorm.
 * User: 13064
 * Date: 2018/12/2
 * Time: 17:15
 */

namespace app\admin\controller;

use think\Controller;
use think\Db;
use think\Request;
class Admincontroller extends Controller
{
    public function _initialize()
    {
        if (empty(session("admin['access']"))){
            return $this->success('请登录', url('admin/Login/index'));
        }
        $request = Request::instance();

        $mname = $request->module();
        $aname = $request->action();
        $cname = $request->controller();
//        var_dump($mname,$cname,$aname);
        $nodelist = session("admin['access']");
        $nodelist = unserialize($nodelist);

        if (session("admin['name']") != 'lkk') {

            $list1 = array();$list2 = array();
            foreach ($nodelist as $k => $v) {
                $list1['controllerName'][] = $v['controllerName'];
                $list2['testname'][] = $v['controllerName'].$v['method'];
            }
            $tname = $cname.$aname;
//            var_dump($list1, $list2, $tname);

            if( in_array($cname,$list1['controllerName'])){
                if(!in_array($tname,$list2['testName']))
                {
                    $this->error("抱歉！没有操作权限！");exit;
                }

            }else
            {
                $this->error("抱歉！没有操作权限！");exit;
            }
//
        }
    }
}